package cn.yunbamboos.rest.service.apidoc.meta;

import cn.yunbamboos.rest.service.apidoc.IMeta;
import com.alibaba.fastjson2.JSONObject;

import java.util.HashMap;
import java.util.Map;

public class Response implements IMeta {

    private final String code;
    private String description;
    private final Map<String, MediaType> content = new HashMap<>();

    public Response(String code) {
        this.code = code;
    }

    public String getCode() {
        return code;
    }

    @Override
    public JSONObject toJSON() {
        JSONObject json = new JSONObject();
        json.put("description", description);

        JSONObject content = new JSONObject();
        for (Map.Entry<String, MediaType> entry : this.content.entrySet()) {
            content.put(entry.getKey(), entry.getValue().toJSON());
        }
        json.put("content", content);

        return json;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public void put(String contentType, MediaType mediaType) {
        this.content.put(contentType, mediaType);
    }
}
